import { expenseBillInfo, expenseBillInvoiceList, expenseBillStandardInfo } from "@/services/chargingManage";
import { getUuid } from "@/utils/utils";
import { Table } from "antd"
import React, { useEffect } from "react";

const BillTable = props => {
  const { columns,rowId,current } = props;

  const [loading,setLoading] = React.useState(true)
  const [list,setList] = React.useState([])
  const [totalInfo,setTotalInfo] = React.useState({})

  useEffect(() => {
    getList()
  },[])
  
  const getList = async () => {
    let res = []
    if(current == 0 || current == 1){
      res = await expenseBillStandardInfo({id:rowId})
      if(current == 1){
        const summaryItem = res.find(item => item.name === "合计")?.children?.[0];
        res = res.filter(item => item.name != '合计')        
        setTotalInfo(summaryItem)
      }
    }else if(current == 2){
      res = await expenseBillInfo({id:rowId})
    }   

    setList(res)
    setLoading(false)
  }

  return (
    <div>
      <Table 
        columns={columns}
        dataSource={list}
        scroll={{x:"auto"}}
        rowKey={(record) => getUuid()}
        pagination={false}
        loading={loading}
      />
      {
        current == 1 ? (
          <div style={{marginTop:24}}>
            <span>溢出总价：{totalInfo.overflowAllPrice}</span>
            <span style={{marginLeft:20}}>套餐总价：{totalInfo.packageAllPrice}</span>
            <span style={{margin:"0 20px"}}>优惠折扣：{totalInfo.packageDiscountPrice}</span>
            <span>应付总费用：{totalInfo.realAllPrice}</span>
          </div>
        ) : ''
      }
    </div>
  )
}

export default BillTable